﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using WarehouseManagement.BusinessLogic.BC;

namespace WarehouseManagement.BusinessLogic.DTO
{
    public partial class ExportDetailDTO : INotifyPropertyChanging, INotifyPropertyChanged
    {

        private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);

        private System.Guid _Id;

        private System.DateTime _CreatedDate;

        private int _MerchandiseId;

        private double _Quantity;

        private decimal _ExportPrice;

        private decimal _OriginalPrice;

        private System.Nullable<decimal> _Profit;

        private string _CreatedBy;

        private DateTime? _LastModifiedDate;

        private string _LastModifiedUser;

        private bool _IsCancelled;

        private System.Guid _ExportId;



        #region Extensibility Method Definitions
        partial void OnLoaded();
        partial void OnValidate(System.Data.Linq.ChangeAction action);
        partial void OnCreated();
        partial void OnIdChanging(System.Guid value);
        partial void OnIdChanged();
        partial void OnCreatedDateChanging(System.DateTime value);
        partial void OnCreatedDateChanged();
        partial void OnMerchandiseIdChanging(int value);
        partial void OnMerchandiseIdChanged();
        partial void OnQuantityChanging(double value);
        partial void OnQuantityChanged();
        partial void OnExportPriceChanging(decimal value);
        partial void OnExportPriceChanged();
        partial void OnOriginalPriceChanging(decimal value);
        partial void OnOriginalPriceChanged();
        partial void OnProfitChanging(System.Nullable<decimal> value);
        partial void OnProfitChanged();
        partial void OnCreatedByChanging(string value);
        partial void OnCreatedByChanged();
        partial void OnLastModifiedDateChanging(DateTime? value);
        partial void OnLastModifiedDateChanged();
        partial void OnLastModifiedUserChanging(string value);
        partial void OnLastModifiedUserChanged();
        partial void OnIsCancelledChanging(bool value);
        partial void OnIsCancelledChanged();
        partial void OnExportIdChanging(System.Guid value);
        partial void OnExportIdChanged();
        #endregion

        public ExportDetailDTO()
        {

            OnCreated();
            Id = Guid.NewGuid();
        }


        public System.Guid Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                if ((this._Id != value))
                {
                    this.OnIdChanging(value);
                    this.SendPropertyChanging();
                    this._Id = value;
                    this.SendPropertyChanged("Id");
                    this.OnIdChanged();
                }
            }
        }


        public System.DateTime CreatedDate
        {
            get
            {
                return this._CreatedDate;
            }
            set
            {
                if ((this._CreatedDate != value))
                {
                    this.OnCreatedDateChanging(value);
                    this.SendPropertyChanging();
                    this._CreatedDate = value;
                    this.SendPropertyChanged("CreatedDate");
                    this.OnCreatedDateChanged();
                }
            }
        }


        public int MerchandiseId
        {
            get
            {
                return this._MerchandiseId;
            }
            set
            {
                if ((this._MerchandiseId != value))
                {

                    this.OnMerchandiseIdChanging(value);
                    this.SendPropertyChanging();
                    this._MerchandiseId = value;
                    this.SendPropertyChanged("MerchandiseId");
                    this.OnMerchandiseIdChanged();
                }
            }
        }

        public string MerchandiseUnit
        {
            get
            {
                var bc = new MerchandiseBC();
                var entity = bc.GetMerchandiseById(this._MerchandiseId);
                if (entity != null)
                {
                    bc = null;
                    return entity.Unit;
                }
                bc = null;
                return null;

            }
        }

        public double Quantity
        {
            get
            {
                return this._Quantity;
            }
            set
            {
                if ((this._Quantity != value))
                {
                    this.OnQuantityChanging(value);
                    this.SendPropertyChanging();
                    this._Quantity = value;
                    this.SendPropertyChanged("Quantity");
                    this.OnQuantityChanged();
                }
            }
        }

        public double AvailableExportQuantity
        {
            get;
            set;
        }

        public decimal ExportPrice
        {
            get
            {
                return this._ExportPrice;
            }
            set
            {
                if ((this._ExportPrice != value))
                {
                    this.OnExportPriceChanging(value);
                    this.SendPropertyChanging();
                    this._ExportPrice = value;
                    this.SendPropertyChanged("ExportPrice");
                    this.OnExportPriceChanged();
                }
            }
        }

        public decimal OriginalPrice
        {
            get
            {
                return this._OriginalPrice;
            }
            set
            {
                if ((this._OriginalPrice != value))
                {
                    this.OnOriginalPriceChanging(value);
                    this.SendPropertyChanging();
                    this._OriginalPrice = value;
                    this.SendPropertyChanged("OriginalPrice");
                    this.OnOriginalPriceChanged();
                }
            }
        }

        public System.Nullable<decimal> Profit
        {
            get
            {
                return this._Profit;
            }
            set
            {
                if ((this._Profit != value))
                {
                    this.OnProfitChanging(value);
                    this.SendPropertyChanging();
                    this._Profit = value;
                    this.SendPropertyChanged("Profit");
                    this.OnProfitChanged();
                }
            }
        }

        public decimal TotalUnitPrice
        {
            get
            {
                return this.ExportPrice * (decimal)this.Quantity;
            }
        }

        public string CreatedBy
        {
            get
            {
                return this._CreatedBy;
            }
            set
            {
                if ((this._CreatedBy != value))
                {

                    this.OnCreatedByChanging(value);
                    this.SendPropertyChanging();
                    this._CreatedBy = value;
                    this.SendPropertyChanged("CreatedBy");
                    this.OnCreatedByChanged();
                }
            }
        }

        public DateTime? LastModifiedDate
        {
            get
            {
                return this._LastModifiedDate;
            }
            set
            {
                if ((this._LastModifiedDate != value))
                {
                    this.OnLastModifiedDateChanging(value);
                    this.SendPropertyChanging();
                    this._LastModifiedDate = value;
                    this.SendPropertyChanged("LastModifiedDate");
                    this.OnLastModifiedDateChanged();
                }
            }
        }

        public string LastModifiedUser
        {
            get
            {
                return this._LastModifiedUser;
            }
            set
            {
                if ((this._LastModifiedUser != value))
                {
                    this.OnLastModifiedUserChanging(value);
                    this.SendPropertyChanging();
                    this._LastModifiedUser = value;
                    this.SendPropertyChanged("LastModifiedUser");
                    this.OnLastModifiedUserChanged();
                }
            }
        }

        public bool IsCancelled
        {
            get
            {
                return this._IsCancelled;
            }
            set
            {
                if ((this._IsCancelled != value))
                {
                    this.OnIsCancelledChanging(value);
                    this.SendPropertyChanging();
                    this._IsCancelled = value;
                    this.SendPropertyChanged("IsCancelled");
                    this.OnIsCancelledChanged();
                }
            }
        }

        public System.Guid ExportId
        {
            get
            {
                return this._ExportId;
            }
            set
            {
                if ((this._ExportId != value))
                {

                    this.OnExportIdChanging(value);
                    this.SendPropertyChanging();
                    this._ExportId = value;
                    this.SendPropertyChanged("ExportId");
                    this.OnExportIdChanged();
                }
            }
        }

        public string MerchandiseName
        {
            get
            {
                var bc = new MerchandiseBC();
                var thisItem = bc.GetMerchandiseById(this._MerchandiseId);
                if (thisItem != null)
                    return thisItem.MerchandiseName;
                return null;
            }
        }


        public bool IsSaved { get; set; }
        public event PropertyChangingEventHandler PropertyChanging;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void SendPropertyChanging()
        {
            if ((this.PropertyChanging != null))
            {
                this.PropertyChanging(this, emptyChangingEventArgs);
            }
        }

        protected virtual void SendPropertyChanged(String propertyName)
        {
            if ((this.PropertyChanged != null))
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
